package com.chx.controller;

import com.chx.dto.StockOutOrderDto;
import com.chx.dto.StockOutOrderPageQueryDto;
import com.chx.result.PageResult;
import com.chx.result.Result;
import com.chx.service.StockOutOrderService;
import com.chx.vo.StockOutOrderVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author cp-月入过万
 * @Date 2025/5/31
 * 出库订单相关接口
 */
@RestController
@RequestMapping("/admin/stock-out-order")
@Api(tags = "出库订单相关接口")
@Slf4j
public class StockOutOrderController {
    @Autowired
    private StockOutOrderService stockOutOrderService;

    /**
     * 新增出库订单
     */
    @ApiOperation(value = "新增出库订单")
    @PostMapping
    public Result<String> save(@RequestBody StockOutOrderDto stockOutOrderDto) {
        log.info("新增出库订单：{}", stockOutOrderDto);
        stockOutOrderService.save(stockOutOrderDto);
        return Result.success();
    }

    /**
     * 修改出库订单
     */
    @ApiOperation(value = "修改出库订单")
    @PutMapping
    public Result<String> update(@RequestBody StockOutOrderDto stockOutOrderDto) {
        log.info("修改出库订单：{}", stockOutOrderDto);
        stockOutOrderService.update(stockOutOrderDto);
        return Result.success();
    }
    /**
     * 审核订单状态
     */
    @ApiOperation(value = "审核订单状态")
    @PutMapping("/status/{id}")
    public Result<String> updateStatus(@PathVariable Long id) {
        log.info("审核订单状态：{}", id);
        stockOutOrderService.updateStatus(id);
        return Result.success();
    }
    /**
     * 提交出库订单
     */
    @ApiOperation(value = "提交出库订单")
    @PostMapping("/status/{id}")
    public Result<String> commit(@PathVariable Long id) {
        log.info("提交出库订单：{}", id);
        stockOutOrderService.commit(id);
        return Result.success();
    }
    /**
     * 根据id查询出库订单
     */
    @ApiOperation(value = "根据id查询出库订单")
    @GetMapping("/{id}")
    public Result<StockOutOrderVo> getById(@PathVariable Long id) {
        log.info("根据id查询出库订单：{}", id);
        StockOutOrderVo stockOutOrderVo = stockOutOrderService.getById(id);
        return Result.success(stockOutOrderVo);
    }
    /**
     * 分页查询出库订单
     */
    @ApiOperation(value = "分页查询出库订单")
    @GetMapping("/page")
    public Result<PageResult> page(StockOutOrderPageQueryDto stockOutOrderPageQueryDto) {
        log.info("分页查询出库订单：{}", stockOutOrderPageQueryDto);
        PageResult pageResult = stockOutOrderService.page(stockOutOrderPageQueryDto);
        return Result.success(pageResult);
    }
}
